// pages/commodity_examine/commodity_examine.js
import basesup from '~/utils/supplier.js'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        keyword: "",
        tabactive: '1',
        pages: 1,
        producdata: [],
        startsnum: {
        },
    },
    tabonChange(items) {
        console.log(items)
        this.setData({
            tabactive: items.detail.name,
            pages: 1,
        })
        if (items.detail.name == '2' ) {
            // 上架全部
            this.productalllistdowm()
        } else if  (items.detail.name == '999') {
            // 上架全部
            this.productalllistup()
        } else {
            // 状态查询
            this.productlist()
        }
        
    },
    async productalllistup() {
        let reqdata = {
            "keyword": this.data.keyword,
            "current": this.data.pages,
            "pageSize": "10",
            "shelfStatus": 1,
        }
        let resdata = await basesup.productalllist(reqdata)
        if (resdata.code == 200) {
            this.setData({
                producdata: resdata.data.result.Data
            })
        }
    },
    async productalllistdowm() {
        let reqdata = {
            "keyword": this.data.keyword,
            "current": this.data.pages,
            "pageSize": "10",
            "shelfStatus": 2,
        }
        let resdata = await basesup.productalllist(reqdata)
        if (resdata.code == 200) {
            this.setData({
                producdata: resdata.data.result.Data
            })
        }
    },
    async productlist() {
        let reqdata = {
            "keyword": this.data.keyword,
            "current": this.data.pages,
            "pageSize": "10",
            "auditStatus": this.data.tabactive,
        }
        let resdata = await basesup.productlist(reqdata)
        if (resdata.code == 200) {
            this.setData({
                producdata: resdata.data.result.Data
            })
        }
    },


    async getprocount() {
        let resdata = await basesup.productcount()
        this.setData({
            startsnum:{}
        })
        if (resdata.code == 200) {
            for (const star in resdata.data.result.auditStatus) {
                if (resdata.data.result.auditStatus[star].audit_status == 1) {
                    this.setData({
                        'startsnum.audit_status1': resdata.data.result.auditStatus[star].count
                    })
                    console.log("01")
                }
                
                if (resdata.data.result.auditStatus[star].audit_status == 3) {
                    this.setData({
                        'startsnum.audit_status3': resdata.data.result.auditStatus[star].count
                    })
                }
            }
            for (const alls in resdata.data.result.shelfStatus) {
                if (resdata.data.result.shelfStatus[alls].shelf_status == 1) {
                    this.setData({
                        'startsnum.shelf_status1': resdata.data.result.shelfStatus[alls].count
                    })
                }
                if (resdata.data.result.shelfStatus[alls].shelf_status == 2) {
                    this.setData({
                        'startsnum.shelf_status2': resdata.data.result.shelfStatus[alls].count
                    })
                }
            }
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.productlist()
        this.getprocount()
    },
    async downOff(items) {
        let reqdata = {
            "id": items.currentTarget.dataset.select,
            "type": "1"
        }
        let resdata = await basesup.upOrDown(reqdata)
        if (resdata.code == 200) {
            wx.showToast({
                title: '下架成功',
                icon: 'none',
                duration: 2000
            })
        }
        this.productalllistdowm()
        this.getprocount()
    },
    async upopen(items){
        let reqdata = {
            "id": items.currentTarget.dataset.select,
            "type": "2"
        }
        let resdata = await basesup.upOrDown(reqdata)
        if (resdata.code == 200) {
            wx.showToast({
                title: '上架成功',
                icon: 'none',
                duration: 2000
            })
        }
        this.productalllistup()
        this.getprocount()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})